<template>
	<view>
		<button class="login_btn"open-type="getUserInfo" @getuserinfo="signIn" onError="onAuthError" scope='userInfo'>
		    会员基础信息授权
		</button>
	</view>
</template>
<script>
	export default {
		name: "login-com",
		props: {
			title: {
				type: String,
				default: ""
			}
		},
		data() {
			return {
				userInfo:{},
				authenticationinfo:{},
			}
		},
		methods: {
			signIn(){
				uni.login({
					provider: 'weixin',
					success: (loginRes)=> {
						console.log(loginRes); // 获取用户信息 
						uni.getUserInfo({
							provider: 'weixin',
							withCredentials:true,  
							success: (res)=> {
								 let userInfo = res.userInfo;
								 this.userInfo = userInfo;
								 this.register(loginRes.code)
								 console.log(userInfo)
							}
						});
					}
				});
			},
			register(authCode){
				this.$get('user/third',{
					code:authCode,
					nickname:this.userInfo.nickName,
					avatar:this.userInfo.avatarUrl,
				},(res)=>{
					this.noCode = false;
					var token = res.userinfo.token;
					uni.setStorageSync('token', token);
					this.$parent.hasLogin = true;
					console.log(this.$parent)
				})
			},
		}
	}
</script>
<style>
	.login_btn{
		opacity: 0;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
	}
</style>
